//
//  JWCoreAnimationHelper.m
//  SiqiCalendar
//
//  Created by sunjiawen on 2018/4/17.
//  Copyright © 2018年 sjw. All rights reserved.
//

#import "JWCoreAnimationHelper.h"

@implementation JWCoreAnimationHelper
static JWCoreAnimationHelper *instance = nil;
/** 单例 */
+ (instancetype)defaultManager {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (instance == nil) {
            instance = [[JWCoreAnimationHelper alloc]init];
        }
    });
    return instance;
}

/**
 暂停layer动画

 @param layer layer
 */
- (void)pauseLayer:(CALayer*)layer
{
    CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
    layer.speed = 0.0;
    layer.timeOffset = pausedTime;
}

/**
 恢复layer动画
 
 @param layer layer
 */
- (void)resumeLayer:(CALayer*)layer
{
    CFTimeInterval pausedTime = [layer timeOffset];
    layer.speed = 1.0;
    layer.timeOffset = 0.0;
    layer.beginTime = 0.0;
    CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
    layer.beginTime = timeSincePause;
}
@end
